// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

Vue.config.productionTip = false
//注册到vue原型上
import clipboard from 'clipboard';
Vue.prototype.clipboard = clipboard;
// rem
import 'amfe-flexible'
// 图标字体
import 'font-awesome/css/font-awesome.min.css'
// mui
import './assets/mui/css/mui.css'
import mui from './assets/mui/js/mui'
Vue.prototype.mui = mui
// vue-awesome-mui
import 'vue-awesome-mui/mui/dist/css/mui.css'
import Mui from 'vue-awesome-mui'
Vue.use(Mui)
// swiper
import 'swiper/dist/css/swiper.css';
// mint-ui
import 'mint-ui/lib/style.css';
import Mint from 'mint-ui';
Vue.use(Mint);
//vuex
import store from './store/index.js'
//axios
import axios from './axios'
Vue.prototype.$axios = axios
//api
import address from './api/api'
Vue.prototype.address = address
//语种切换
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
// 多语言实例
import en from './assets/i18n/en'
import zh from './assets/i18n/zh'
const i18n = new VueI18n({
  locale: (function () {
    if (localStorage.getItem('lang')) {
      return localStorage.getItem('lang')
    }
    return 'zh'
  }()),
  messages: {
    'zh': zh,   // 中文语言包
    'en': en   // 英文语言包 
  }
})
//router
router.beforeEach((to, from, next) => {
  store.state.userMsg = localStorage.getItem('userMsg')//获取本地存储的token
  if (to.meta.requireAuth) {  // 判断该路由是否需要登录权限
    if (store.state.userMsg !== null || '') {  // 通过vuex state获取当前的token是否存
      next();
    }
    else {
      Mint.Toast({message: "该页面需要登陆",});
      next({
        path: '/login',
      })
    }
  }
  else {
    next();
  }
})




new Vue({
  el: '#app',
  store,
  router,
  i18n,
  components: { App },
  template: '<App/>'
})
